<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-07-30 20:02:30
 * @LastEditTime: 2020-02-28 11:25:38
 * @LastEditors: Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../css/base.css" />
    <link rel="stylesheet" href="../css/elementui.css">
    <script type="text/javascript" src="../script/vue.min.js"></script>
    <script type="text/javascript" src="../script/vant.min.js"></script>
    <script type="text/javascript" src="../script/fastclick.js"></script>
    <script type="text/javascript" src="../script/jquery.js"></script>

    <script type="text/javascript" src="../script/base.js"></script>
    <script type="text/javascript" src="../script/ajaxFileUpload.js"></script>
    <script type="text/javascript" src="../script/layer/mobile/layer.js"></script>

    <script src="../script/elementui.js"></script>

    <style>
        .box {
            width: 100%;
            display: flex;
            flex-direction: column;
        }

        .form {
            width: 100%;
            height: auto;
        }

        .content {
            position: relative;
            padding: 0 50px;
        }

        .van-field {
            width: 33%;
            float: left;
        }

        .van-cell {
            background-color: transparent;
        }

        .van-field__control {
            border-bottom: 2px solid #e6c678;
        }

        .van-cell::after {
            border-bottom: 0;
        }

        .van-cell {
            background-color: transparent;
        }

        .van-cell::after {
            border-bottom: 0;
        }

        .head .van-row .van-col,
        .content .van-row .van-col {
            margin-bottom: 8px;
            text-align: center;
            font-weight: 300;
            color: #e6c678;
            font-size: 14px;
        }

        .content .van-row .van-col .van-field {
            padding: 0;
            background: #fff;
            border: 1px solid #cecece;
            border-radius: 5px;
        }

        .content .van-row .van-col .van-field__control {
            color: #000;
        }

        @keyframes load {
            0% {
                box-shadow: inset 0px 0px 100px 10px rgba(61, 134, 208, 0.6);
            }

            100% {
                box-shadow: inset 0px 0px 20px 10px rgba(61, 134, 208, 0.1);
            }
        }

        .right-button .van-button {
            margin-left: 5px;
            min-width: 100px;
        }

        .scanImg img {
            width: 40px;
            height: 40px;
        }

        .scanPop {
            width: 160px;
            height: 180px;
            text-align: center;
            background-color: transparent;
            margin: 0;
            padding: 0;
        }

        .van-icon-enlarge {
            font-size: 150px;
            color: #e6c678;
            margin: 0;
            padding: 0;
        }

        .inputClass {
            opacity: 0;
            width: 150px;
        }

        .scanLine {
            position: absolute;
            z-index: 2;
            width: 66%;
            height: 2px;
            transform: translateX(25%);
            background-color: #e6c678;
            animation: scanLineMove 2s infinite;
        }

        .newClass {
            color: red;
        }

        @keyframes scanLineMove {
            from {
                top: 30px;
            }

            to {
                top: 120px;
            }
        }

        .van-icon-arrow-left {
            position: absolute;
            top: 120px;
            right: 0;
            font-size: 20px;
            font-weight: 700;
            z-index: 999999;
        }

        .boxListPOP {
            width: 70%;
            height: 100%;
            background-color: #212022;
            color: #fff;
            border: 1px solid #e6c678;
        }

        .boxListBox {
            width: 100%;
            height: 100%;
            overflow-y: auto;
        }

        .boxListPOP .van-field {
            width: 100%;
        }

        .table table tr td .van-checkbox__icon--square {
            margin: auto;
        }

        .boxListPOP .boxDelete {
            width: 100%;
            display: flex;
        }

        .van_uploaderDiv {
            width: 500px;
            height: 55px;
            line-height: 55px;
        }

        .van_uploader {
            padding: 0;
            margin: 0;
        }

        .van_uploader .van-field__control {
            border-bottom: none !important;
        }

        .van_deleteDiv {
            width: 25px;
            height: 25px
        }

        .van_uploaderi {
            font-size: 25px
        }

        .van-uploader_Div {
            width: 50px;
            height: 50px;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="box">
            <div class="content">
                <van-icon name="arrow-left" color="#e6c678" v-show="!showBoxList" @click="arrowLeftClick"></van-icon>
                <div class="form">
                    <van-field v-model="formData.EquipmentName" label="机台：" readonly @click="openBaseScreen('机台')">
                    </van-field>
                    <van-field v-model="formData.productname" label="零件名称：" readonly @click="openBaseScreen('模具')">
                    </van-field>
                    <van-field v-model="formData.CreateTime" label="检查日期：" readonly></van-field>
                    <van-field v-model="formData.Creater" label="负责人：" readonly @click="handlerCreater">
                    </van-field>
                    <van-field v-model="formData.Question" label="问题点：">
                    </van-field>
                    <van-field v-model="formData.SValue" label="标准值：">
                    </van-field>
                    <van-field v-model="formData.AValue" label="实际值：">
                    </van-field>
                    <van-field v-model="formData.AEStatus" label="辅助设备状态：">
                    </van-field>
                    <van-field v-model="formData.IControlName" label="受控状态：" readonly @click="IControlShow = true">
                    </van-field>
                    <van-field v-model="formData.DDays" label="持续天数：">
                    </van-field>

                    <van-field v-model="formData.FRemarks" label="备注：">
                    </van-field>
                    <!-- <div class="van_uploaderDiv"> -->
                    <!-- </div> -->
                    <van-field name="uploader" style="width: 50%;" label="改造前照片：" readonly class="van_uploader"
                        style="border-bottom: none;">
                        <template #input>
                            <div class="van-uploader">
                                <!-- 整行图片 -->
                                <div class="van-uploader__wrapper">
                                    <!-- 单个照片 -->
                                    <div class="van-uploader__preview" v-for="(ite, idx) in formData.GZQPicture">
                                        <van-image @click="previewImg(2)" width="50" height="50"
                                            :src="serverIP + ite.url">
                                        </van-image>
                                        <div @click="deleteImg(2,idx)"
                                            class="van-uploader__preview-delete  van_deleteDiv">
                                            <i
                                                class="van-icon van-icon-cross van-uploader__preview-delete-icon  van_uploaderi  "></i>
                                        </div>
                                    </div>
                                    <!-- 上传图片的按钮 -->
                                    <!-- <div v-show="formData.GZQPicture.length < 1" -->
                                    <div v-show="formData.GZQPicture.length < 1"
                                        class="van-uploader__upload  van-uploader_Div" @change="uploadNewFile(2)">
                                        <i
                                            class="van-badge__wrapper van-icon van-icon-photograph van-uploader__upload-icon"></i>
                                        <input type="file" :name="'newFile2'" :id="'newFile2'" accept="image/*"
                                            class="van-uploader__input">
                                    </div>
                                </div>
                            </div>
                        </template>
                    </van-field>
                    <van-field name="uploader" style="width: 50%;" label="改正后照片：" readonly class="van_uploader"
                        style="border-bottom: none;">
                        <template #input>
                            <div class="van-uploader">
                                <!-- 整行图片 -->
                                <div class="van-uploader__wrapper">
                                    <!-- 单个照片 -->
                                    <div class="van-uploader__preview" v-for="(ite, idx) in formData.GZHPicture">
                                        <van-image @click="previewImg(1)" width="50" height="50"
                                            :src="serverIP + ite.url">
                                        </van-image>
                                        <div @click="deleteImg(1,idx)"
                                            class="van-uploader__preview-delete  van_deleteDiv">
                                            <i
                                                class="van-icon van-icon-cross van-uploader__preview-delete-icon  van_uploaderi  "></i>
                                        </div>
                                    </div>
                                    <!-- 上传图片的按钮 -->
                                    <!-- <div v-show="formData.GZHPicture.length < 1" -->
                                    <div v-show="formData.GZHPicture.length < 1"
                                        class="van-uploader__upload  van-uploader_Div" @change="uploadNewFile(1)">
                                        <i
                                            class="van-badge__wrapper van-icon van-icon-photograph van-uploader__upload-icon"></i>
                                        <input type="file" :name="'newFile1'" :id="'newFile1'" accept="image/*"
                                            class="van-uploader__input">
                                    </div>
                                </div>
                            </div>
                        </template>
                    </van-field>


                </div>
            </div>

            <div class="bottom">
                <div class="left-content">
                </div>
                <div class="right-button flex-box">
                    <van-button color="#e6c678" :disabled="ifConfirm" :loading="ifConfirm" loading-text="请稍后..."
                        @click="confirmSub" block>提 &nbsp &nbsp 交</van-button>
                </div>
            </div>
        </div>

        <van-action-sheet v-model="IControlShow" :actions="IControlActions" @select="onSelectIControl">
        </van-action-sheet>

        <van-popup v-model="scanShow" class="scanPop">
            <div class="scanLine"></div>
            <van-icon name="enlarge"></van-icon>
            <input type="text" class="inputClass" inputmode="none" inputmode="none" id="autoInput" autofocus ref="input"
                @onkeyup="inputFocus(event)"></input>
            <!-- <input id="autoInput" class="inputClass" type="number" v-model="inputCode" ref="input" autofocus
                @keyup.enter="inputFocus()"> -->
        </van-popup>

        <van-popup class="boxListPOP" v-model="showBoxList" position="right">
            <div class="boxListBox">
                <div class="table tableScroll">
                    <table>
                        <tr>
                            <th>机台号</th>
                            <th>零件名称</th>
                            <th>检查日期</th>
                            <th>负责人</th>
                            <th>问题点</th>
                            <th>标准值</th>
                            <th>实际值</th>
                            <th>辅助设备状态</th>
                            <th>受控状态</th>
                            <th>持续天数</th>
                        </tr>
                        <tr v-for="item in boxList">
                            <td>{{item.EquipmentCode}}</td>
                            <td>{{item.productname}}</td>
                            <td>{{item.CreateTime}}</td>
                            <td>{{item.Creater}}</td>
                            <td>{{item.Question}}</td>
                            <td>{{item.SValue}}</td>
                            <td>{{item.AValue}}</td>
                            <td>{{item.AEStatus}}</td>
                            <td>{{item.IControl}}</td>
                            <td>{{item.DDays}}</td>
                        </tr>
                    </table>
                </div>
            </div>
        </van-popup>
    </div>
</body>

<script type="text/javascript">

    var vm;
    apiready = function () {
        var photoBrowser = api.require('photoBrowser');

        api.addEventListener({
            name: 'selectRow'
        }, function (ret, err) {
            var type = ret.value.type;
            var row = ret.value.row;
            if (type == '模具') {
                vm.formData.MouldID = row.MouldID;
                vm.formData.MouldNo = row.MouldNo;
            }
        })

        vm = new Vue({
            el: '#app',
            data: {
                formData: {
                    EquipmentName: api.pageParam.equipment.EquipmentName,
                    EquipmentID: api.pageParam.equipment.EquipmentID,
                    productname: '',
                    productid: '',
                    CreateTime: APP.getFormatDate().split(' ')[0],
                    Creater: window.localStorage.getItem('loginName'),
                    Question: '',
                    SValue: '',
                    AValue: '',
                    AEStatus: '',
                    IControl: '',
                    IControlName: '',
                    DDays: '',
                    FRemarks: '',
                    GZHPicture: [],
                    GZQPicture: []
                },
                ifConfirm: false,
                scanShow: false,
                // inputCode: '',
                IControlShow: false,
                IControlActions: [
                    {
                        name: '是',
                        value: 1
                    },
                    {
                        name: '否',
                        value: 0
                    }
                ],
                showBoxList: false,
                boxList: [],
                serverIP: 'http://' + APP.serverIP()
            },
            created: function () {
                var that = this;
                that.openScan()

                if (window.localStorage.getItem('clientHeight') != 752) {
                    document.getElementById('app').style.zoom = 0
                } else {
                    document.getElementById('app').style.zoom = 1.5
                }

                console.log('api', JSON.stringify(api.pageParam))
                that.getInitData()
            },
            mounted() {
                APP.keyBoardChange()
                window.addEventListener('keyup', this.inputFocus);
            },
            methods: {
                openScan() {
                    var that = this
                    var resultList = api.hasPermission({
                        list: ['camera']
                    });
                    if (resultList[0].granted) {
                        // 已授权，可以继续下一步操作
                        console.log(JSON.stringify(resultList))

                        // that.uploadNewFile(index, idx)
                    } else {
                        api.confirm({
                            msg: '应用需要您的授权才能访问相机',
                            buttons: ['取消', '去设置']
                        }, function (ret) {
                            if (ret.buttonIndex == 2) {
                                api.requestPermission({
                                    list: ['camera'],
                                }, function (res) {
                                    if (res.list[0].granted) {
                                        // 已授权，可以继续下一步操作
                                        // that.uploadNewFile(index, idx)
                                    }
                                });
                            }
                        });
                    }
                },


                previewImg(index) {
                    var that = this
                    document.activeElement.blur();
                    var imgFlag = 0
                    var imageArr = []
                    if (index == 1) {
                        that.formData.GZHPicture.map((item) => {
                            imageArr.push(that.serverIP + item.url)
                        })
                    } else {
                        that.formData.GZQPicture.map((item) => {
                            imageArr.push(that.serverIP + item.url)
                        })
                    }

                    photoBrowser.open({
                        images: imageArr,
                        bgColor: '#000'
                    }, function (ret, err) {
                        if (ret) {
                            // alert(JSON.stringify(ret));
                            if (ret.eventType == 'show') {
                                imgFlag = 1
                            }
                            if (ret.eventType == 'click') {
                                imgFlag = 0
                                photoBrowser.close();
                            }
                        } else {
                            layer.open({
                                content: '图片打开失败，请重试！',
                                skin: 'msg',
                                time: 2
                            });
                        }
                    });
                },

                deleteImg(index, idx) {
                    var that = this
                    if (index == 1) {
                        that.formData.GZHPicture.splice(idx, 1)
                    }
                    else {
                        that.formData.GZQPicture.splice(idx, 1)
                    }
                },

                uploadNewFile(index) {
                    var that = this
                    var url = that.serverIP + '/Frame/uploadImgFile?dirName=工艺审核';
                    console.log(url);
                    // APP.serverIP()
                    $.ajaxFileUpload({
                        type: 'POST',
                        url: url,
                        secureuri: false,
                        fileElementId: 'newFile' + index,
                        dataType: 'json',
                        success: function (res, status) {
                            if (res.status == 200) {
                                console.log(JSON.stringify(res.data.origin))
                                if (index == 1) {
                                    that.formData.GZHPicture.push({ url: res.data.origin })

                                } else {
                                    that.formData.GZQPicture.push({ url: res.data.origin })


                                }
                                // console.log('55555555' + JSON.stringify(that.tableData[idx].imgList))
                            } else {
                                vm.$toast('上传失败');
                            }
                        },
                        error: function (data, status, e) {
                            console.log('失败data', JSON.stringify(data))
                        }

                    });

                },
                handlerCreater() {
                    var that = this
                    that.scanShow = true
                    $('#autoInput').val('');
                    $("#autoInput").focus();
                },
                arrowLeftClick() {
                    var that = this
                    that.showBoxList = true
                    var obj = {
                        type: 1,
                        EquipmentID: that.formData.EquipmentID
                    }
                    console.log('obj', JSON.stringify(obj))
                    APP.ajax('selectGY', obj, function (res) {
                        console.log('res', JSON.stringify(res))
                        res.ds.map((item) => {
                            item.CreateTime = item.CreateTime.replace('T', ' ')
                        })
                        that.boxList = res.ds
                    })
                },
                getInitData() {
                    var that = this
                    var obj = {
                        type: 0,
                        EquipmentID: that.formData.EquipmentID
                    }
                    console.log('obj', JSON.stringify(obj))
                    APP.ajax('selectGY', obj, function (res) {
                        console.log('res', JSON.stringify(res))
                        that.formData.productname = res.ds[0].Productname
                        that.formData.productid = res.ds[0].productid
                    })
                },
                onSelectIControl(val) {
                    var that = this
                    that.formData.IControlName = val.name
                    that.formData.IControl = val.value
                    that.IControlShow = false
                },
                openBaseScreen: function (str) {
                    var that = this;
                    var obj;
                    if (str == '模具') {
                        obj = {
                            allowClear: false,
                            showSearch: true,
                            searchKey: '',
                            serverSearch: false,
                            searchBy: ['MouldNo'],
                            isPaging: false,
                            type: str,
                            cmd: 'getZSMould',
                            param: {
                            }
                        }
                    }

                    api.openWin({
                        name: 'baseScreen',
                        url: 'common/baseScreen.html',
                        reload: true,
                        slidBackEnabled: false,
                        pageParam: obj
                    })
                },
                inputFocus(e) {
                    var that = this
                    if (e.keyCode == 13) {
                        let InputData = $("#autoInput").val().replace(" ", "").replace(" ", "");
                        // 进行扫描数据的处理
                        that.$refs.input.setAttribute('readonly', 'readonly');
                        console.log('InputData', JSON.stringify(InputData))
                        api.toast({
                            msg: InputData
                        })
                        if (InputData) {
                            APP.ajax('ZS_CardLogin', { P_Card: InputData }, function (res) {
                                if (res.ds[0].status == 200) {
                                    that.formData.Creater = res.ds[0].Name
                                    that.scanShow = false
                                } else {
                                    vm.$toast(res.ds[0].msg);
                                }
                            })
                        } else {
                            that.$refs.input.removeAttribute('readonly');
                            api.toast({
                                msg: '暂无此卡号的信息！'
                            })
                        }
                        $('#autoInput').val('');
                        $("#autoInput").focus();
                    }
                },
                confirmSub() {
                    var that = this
                    var obj = {
                        EquID: that.formData.EquipmentID,
                        Question: that.formData.Question,
                        ProductID: that.formData.productid,
                        SValue: that.formData.SValue,
                        AValue: that.formData.AValue,
                        AEStatus: that.formData.AEStatus,
                        IControl: that.formData.IControl,
                        Creater: that.formData.Creater,
                        FRemarks: that.formData.FRemarks,
                        GZHPicture: that.formData.GZHPicture.map(item => item.url).join(','),
                        GZQPicture: that.formData.GZQPicture.map(item => item.url).join(','),
                    }
                    console.log('obj', JSON.stringify(obj))
                    APP.ajax('insertGY', obj, function (res) {
                        console.log('res', JSON.stringify(res))
                        api.toast({
                            msg: '提交成功！'
                        })
                        api.sendEvent({
                            name: 'refreshBrowser',
                            extra: {
                                breadData: {
                                    name: '工艺上报',
                                    url: 'processReport',
                                    ZS_FunctionID: 0,
                                    click: true
                                }
                            }
                        })
                        api.closeFrame()
                    })
                },
            }
        })
    };
</script>

</html>